package xc.com.cms.client.mq;

import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import xc.com.cms.client.service.CmsPageService;
import xc.com.cms.domain.CmsPage;

import java.util.Map;

@Component
public class ConsumerPostPage {
    private static final Logger LOGGER = LoggerFactory.getLogger(ConsumerPostPage.class);

    @Autowired
    private CmsPageService cmsPageService;
    @RabbitListener(queues = {"${xc.mq.queue}"})
    public void postpage(String msg){
        //解析信息
        Map map = JSON.parseObject(msg, Map.class);
        //获取页面id
        String id = (String)map.get("pageId");
        //校验是否合法
        CmsPage cmsPage = cmsPageService.querycmspagebyid(id);
        //判断是否为空
        if(cmsPage==null){
            LOGGER.error("receive cms post page,cmsPage is null:{}",msg.toString());
            return;
        }
        //获取
        cmsPageService.savepagetoservicepath(id);

    }
}
